<style lang="less">
@import "~assets/styles/table-common.less";
</style>
<template>
<div class="search">
    <Card>
        <Row v-show="openSearch" @keydown.enter.native="handleSearch">
            <Form ref="searchForm" :model="searchForm" inline :label-width="70">
                <Form-item label="公司名称" prop="username">
                    <Input type="text" v-model.trim="searchForm.username" clearable placeholder="请输入公司名称" style="width: 200px" />
                </Form-item>
                <Form-item label="姓名" prop="nickName">
                    <Input type="text" v-model.trim="searchForm.nickName" clearable placeholder="请输入姓名" style="width: 200px" />
                </Form-item>

                <Form-item label="手机" prop="mobile">
                    <Input type="text" v-model.trim="searchForm.mobile" clearable placeholder="请输入手机" style="width: 200px" />
                </Form-item>
                <Form-item label="推送首页" prop="isHome">
                    <Select v-model="searchForm.isHome" placeholder="请选择" clearable style="width: 200px">
                        <Option value="">全部</Option>
                        <Option value="1">是</Option>
                        <Option value="0">否</Option>
                    </Select>
                </Form-item>
                <Form-item label="推荐展商" prop="isRecommend">
                    <Select v-model="searchForm.isRecommend" placeholder="请选择" clearable style="width: 200px">
                        <Option value="">全部</Option>
                        <Option value="1">是</Option>
                        <Option value="0">否</Option>
                    </Select>
                </Form-item>
                <Form-item label="企业认证" prop="status">
                    <Select v-model="searchForm.status" placeholder="请选择" clearable style="width: 200px">
                        <Option value="">全部</Option>
                        <Option value="-1">待认证</Option>
                        <Option value="0">待审核</Option>
                        <Option value="1">已审核</Option>
                        <Option value="9">驳回</Option>
                    </Select>
                </Form-item>
                <Form-item label="CLE展商" prop="isCleExhibitor">
                    <Select v-model="searchForm.isCleExhibitor" placeholder="请选择" clearable style="width: 200px">
                        <Option value="">全部</Option>
                        <Option value="1">是</Option>
                        <Option value="0">否</Option>
                    </Select>
                </Form-item>

                <Form-item style="margin-left:-35px;" class="br">
                    <Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
                    <Button @click="handleReset">重置</Button>
                </Form-item>
            </Form>
        </Row>
        <Row class="operation">
            <Button @click="add" type="primary" icon="md-add">添加IP方</Button>
            <Button @click="delAll" icon="md-trash">批量删除</Button>
            <Button @click="pushHomeAll" type="primary" icon="md-flame">推送首页</Button>
            <Button @click="unPushHomeAll" icon="md-bonfire">取消推送首页</Button>
            <Button @click="showRecommend" type="primary" icon="md-flame">推荐展商</Button>
            <Button @click="unRecommendAll" icon="md-bonfire">取消推荐展商</Button>
            <Button @click="setCleAll" type="primary" icon="md-flame">设置专委会会员</Button>
            <Button @click="unsetCleAll" icon="md-bonfire">取消设置专委会会员</Button>

            <Button @click="cleExhibitorAll" type="primary" icon="md-flame">设置CLE展商</Button>
            <Button @click="uncleExhibitorAll" icon="md-bonfire">取消CLE展商</Button>

            <Button @click="sendMail" icon="md-send">发送邮件</Button>
            <Dropdown @on-click="handleDropdownExport">
                <Button>
                    导出数据
                    <Icon type="md-arrow-dropdown" />
                </Button>
                <DropdownMenu slot="list">
                    <DropdownItem name="search">导出检索数据</DropdownItem>
                    <DropdownItem name="selected">导出选中数据</DropdownItem>
                </DropdownMenu>
            </Dropdown>
            <Dropdown @on-click="handleDropdown" style="margin-top:10px">
                <Button>
                    更多操作
                    <Icon type="md-arrow-dropdown" />
                </Button>
                <DropdownMenu slot="list">
                    <DropdownItem name="refresh">刷新</DropdownItem>
                    <DropdownItem name="reset">重置登录密码</DropdownItem>
                </DropdownMenu>
            </Dropdown>
            <Button type="dashed" @click="openSearch=!openSearch">{{openSearch ? "关闭搜索" : "开启搜索"}}</Button>
            <Button type="dashed" @click="openTip=!openTip">{{openTip ? "关闭提示" : "开启提示"}}</Button>
        </Row>
        <Row v-show="openTip">
            <Alert show-icon>
                已选择
                <span class="select-count">{{selectCount}}</span> 项
                <a class="select-clear" @click="clearSelectAll">清空</a>
            </Alert>
        </Row>
        <Row>
            <Table :loading="loading" border :columns="columns" :data="data" sortable="custom" @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
        </Row>
        <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
        </Row>
    </Card>

    <Modal :title="modalTitle" v-model="modalVisible" :mask-closable="false" :width="500" :styles="{top: '30px'}">

        <Form ref="form" :model="form" :label-width="90" :rules="formValidate">
            <FormItem label="公司名称" prop="username">
                <Input v-model.trim="form.username" autocomplete="off" :maxlength="50" />
            </FormItem>

            <FormItem label="密码" prop="password" v-if="modalType==0" :error="errorPass">
                <span slot="label" class="must">密码</span>
                <Input type="password" password v-model.trim="form.password" autocomplete="off" :maxlength="50" />
            </FormItem>
            <FormItem label="姓名" prop="nickName">
                <Input v-model.trim="form.nickName" autocomplete="off" :maxlength="50" />
            </FormItem>
            <FormItem label="邮箱" prop="email">
                <Input v-model.trim="form.email" :maxlength="50" />
            </FormItem>
            <FormItem label="手机" prop="mobile">
                <Input v-model.trim="form.mobile" :maxlength="50" />
            </FormItem>
            <FormItem label="职位" prop="position">
                <Input v-model.trim="form.position" :maxlength="50" />
            </FormItem>
            <FormItem label="展位号" prop="standNo">
                <Input v-model.trim="form.standNo" :maxlength="20" />
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="text" @click="modalVisible=false">取消</Button>
            <Button type="primary" :loading="submitLoading" @click="submitUser">提交</Button>
        </div>
    </Modal>

    <!-- 自定义导出数据 -->
    <Modal v-model="exportModalVisible" :title="exportTitle" :loading="loadingExport" @on-ok="exportCustomData">
        <Form ref="exportForm" :label-width="85">
            <FormItem label="导出文件名">
                <Input v-model="filename" />
            </FormItem>
            <FormItem label="自定义导出列">
                <CheckboxGroup v-model="chooseColumns">
                    <Checkbox v-for="(item, i) in exportColumns" :label="item.title" :key="i" :value="item.checked" :disabled="item.disabled"></Checkbox>
                </CheckboxGroup>
            </FormItem>
        </Form>
    </Modal>
    <Modal v-model="picVisible" :title="picTitle" draggable>
        <img :src="fileUrl" alt="无效的图片链接" style="width: 100%;margin: 0 auto;display: block;" />
        <div slot="footer">
            <Button @click="picVisible=false">关闭</Button>
        </div>
    </Modal>

    <!-- 排序值弹窗 -->
    <Modal v-model="recommendModalVisible" :title="recommendTitle" @on-ok="recommendAll">
        <Form ref="recommendForm" :label-width="85">
            <FormItem label="排序值">
                <InputNumber :min="1" :max="999999" v-model.trim="sortOrder" style="width:150px;" placeholder="请输入" />
                <span style="margin-left:5px">值越大排名越靠前</span>
            </FormItem>
        </Form>
    </Modal>

    <check-password ref="checkPass" @on-success="resetPass" />
</div>
</template>

<script>
import {
    mapActions
} from 'vuex'

import {
    validateMobile,
    validatePassword
} from "@/libs/validate";
// 指定导出列数据
import {
    exportColumn
} from "@/libs/export/iper-manage/exportColumn";
import excel from "@/libs/excel";
import victorExcel from "@/libs/victorExcel";
import checkPassword from "@/my-components/hboot/check-password";

export default {
    name: "iper-manage",
    components: {
        checkPassword
    },
    data() {
        return {
            sortOrder: 0,
            picVisible: false,
            picTitle: "",
            fileUrl: "",
            //导出部分 开始
            exportModalVisible: false,
            loadingExport: true,
            exportColumns: exportColumn,
            chooseColumns: [],
            filename: "IP方数据",
            exportTitle: "确认导出",
            exportType: "",
            exportData: [],
            //导出部分 结束
            height: 510,
            openSearch: true,
            openTip: true,
            loading: true,
            selectCount: 0,
            selectList: [],
            searchForm: {
                standNo: '',
                username: "",
                nickName: '',
                mobile: '',
                status: "",
                isRecommend: '',
                isCleExhibitor: '',
                isHome: '',
                pageNumber: 1,
                pageSize: 10,
                sort: "iper.createTime",
                order: "desc",
            },
            selectDate: null,
            modalType: 0,
            modalVisible: false,
            modalTitle: "",
            form: {
                username: "",
                nickName: '',
                email: '',
                mobile: '',
                position: '',
                standNo: '',
            },
            errorPass: "",
            formValidate: {
                username: [{
                    required: true,
                    message: "账号不能为空",
                    trigger: "blur"
                }],
                nickName: [{
                    required: true,
                    message: "姓名不能为空",
                    trigger: "blur"
                }],
                mobile: [{
                        required: true,
                        message: "手机号不能为空",
                        trigger: "blur"
                    },
                    {
                        validator: validateMobile,
                        trigger: "blur"
                    }
                ],
                email: [{
                        required: true,
                        message: "请输入邮箱地址"
                    },
                    {
                        type: "email",
                        message: "邮箱格式不正确"
                    }
                ]

            },
            submitLoading: false,
            columns: [{
                    type: "selection",
                    width: 60,
                    align: "center",
                    fixed: "left"
                },
                {
                    type: "index",
                    width: 60,
                    align: "center",
                    fixed: "left"
                },
                {
                    title: "公司名称",
                    key: "username",
                    minWidth: 300,
                    //fixed: "left",
                    render: (h, params) => {
                        let node = [];
                        if (params.row.status == '-1') {
                            node.push(
                                h("Tag", {
                                    props: {
                                        color: "default",
                                    }
                                }, '待认证')
                            );
                        } else if (params.row.status == '0') {
                            node.push(
                                h("Tag", {
                                    props: {
                                        color: "default",
                                    }
                                }, '待审核')
                            );
                        } else if (params.row.status == '1') {
                            node.push(
                                h("Tag", {
                                    props: {
                                        color: "success",
                                    }
                                }, "已审核")
                            );
                        }
                        if (params.row.status == '9') {
                            node.push(
                                h("Tag", {
                                    props: {
                                        color: "error",
                                    }
                                }, "驳回")
                            );
                        }
                        if (params.row.isHome == '1') {
                            node.push(
                                h("Tag", {
                                    props: {
                                        color: "error",
                                    }
                                }, `推送首页`)
                            );
                        }
                        if (params.row.isCle == '1') {
                            node.push(
                                h("Tag", {
                                    props: {
                                        color: "warning",
                                    }
                                }, `专委会会员`)
                            );
                        }
                        if (params.row.isCleExhibitor == '1') {
                            node.push(
                                h("Tag", {
                                    props: {
                                        color: "error",
                                    }
                                }, `CLE展商`)
                            );
                        }
                        if (params.row.isRecommend == '1') {
                            node.push(
                                h("Tag", {
                                    props: {
                                        color: "#FFA2D3",
                                    }
                                }, `推荐展商(${params.row.recommendSortOrder})`)
                            );
                        }

                        node.push(h("span", {}, params.row.username));
                        return h("div", node);

                    },
                },
                {
                    title: "企业LOGO",
                    key: "logo",
                    minWidth: 150,
                    align: "center",
                    render: (h, params) => {
                        if (params.row.logo) {
                            return h("img", {
                                attrs: {
                                    src: params.row.logo,
                                    alt: "加载图片失败"
                                },
                                style: {
                                    cursor: "pointer",
                                    width: "80px",
                                    height: "60px",
                                    margin: "10px 0",
                                    "object-fit": "contain"
                                },
                                on: {
                                    click: () => {
                                        this.showPic(params.row.username, params.row.logo);
                                    }
                                }
                            });
                        } else {
                            return h('div', {}, '暂未上传');
                        }

                    }
                },
                {
                    title: "姓名",
                    key: "nickName",
                    minWidth: 120,
                },
                {
                    title: "手机",
                    key: "mobile",
                    minWidth: 130,
                },
                {
                    title: "邮箱",
                    key: "email",
                    minWidth: 130,
                },
                {
                    title: "职位",
                    key: "position",
                    minWidth: 120,
                },
                {
                    title: "展位号",
                    key: "standNo",
                    minWidth: 120,
                },
                // {
                // 	title: "企业认证",
                // 	key: "status",
                // 	align: "center",
                // 	width: 180,
                // 	render: (h, params) => {
                // 		if (params.row.status == '-1') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "default",
                // 		text: "待认证"
                // 		}
                // 		})
                // 		]);
                // 		}
                // 		if (params.row.status == '0') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "default",
                // 		text: "待审核"
                // 		}
                // 		})
                // 		]);
                // 		} else if (params.row.status == '1') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "success",
                // 		text: "已审核"
                // 		}
                // 		})
                // 		]);
                // 		} else if (params.row.status == '9') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "error",
                // 		text: "驳回"
                // 		}
                // 		})
                // 		]);
                // 		}
                // 	},
                // 	filters: [{
                // 		label: "待认证",
                // 		value: "-1"
                // 		}, {
                // 		label: "待审核",
                // 		value: "0"
                // 		},
                // 		{
                // 		label: "已审核",
                // 		value: "1"
                // 		}, {
                // 		label: "驳回",
                // 		value: "9"
                // 		}
                // 	],
                // 	filterMultiple: false,
                // 	filterMethod(value, row) {
                // 		if (value == "-1") {
                // 		return row.status == "-1";
                // 		} else if (value == "0") {
                // 		return row.status == "0";
                // 		} else if (value == "1") {
                // 		return row.status == "1";
                // 		} else if (value == "9") {
                // 		return row.status == "9";
                // 		}
                // 	}
                // },
                // {
                // 	title: "推送首页",
                // 	key: "isHome",
                // 	align: "center",
                // 	width: 120,
                // 	render: (h, params) => {
                // 		if (params.row.isHome == '1') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "success",
                // 		text: "是"
                // 		}
                // 		})
                // 		]);
                // 		} else if (params.row.isHome == '0') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "error",
                // 		text: "否"
                // 		}
                // 		})
                // 		]);
                // 		}
                // 	},
                // 	filters: [{
                // 		label: "是",
                // 		value: '1'
                // 		},
                // 		{
                // 		label: "否",
                // 		value: '0'
                // 		}
                // 	],
                // 	filterMultiple: false,
                // 	filterMethod(value, row) {
                // 		if (value == '1') {
                // 		return row.isHome == '1';
                // 		} else if (value == '0') {
                // 		return row.isHome == '0';
                // 		}
                // 	}
                // },
                // {
                // 	title: "推荐展商",
                // 	key: "isRecommend",
                // 	align: "center",
                // 	width: 120,
                // 	render: (h, params) => {
                // 		if (params.row.isRecommend == '1') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "success",
                // 		text: "是"
                // 		}
                // 		})
                // 		]);
                // 		} else if (params.row.isRecommend == '0') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "error",
                // 		text: "否"
                // 		}
                // 		})
                // 		]);
                // 		}
                // 	},
                // 	filters: [{
                // 		label: "是",
                // 		value: '1'
                // 		},
                // 		{
                // 		label: "否",
                // 		value: '0'
                // 		}
                // 	],
                // 	filterMultiple: false,
                // 	filterMethod(value, row) {
                // 		if (value == '1') {
                // 		return row.isRecommend == '1';
                // 		} else if (value == '0') {
                // 		return row.isRecommend == '0';
                // 		}
                // 	}
                // },

                // {
                // 	title: "专委会会员",
                // 	key: "isCle",
                // 	align: "center",
                // 	width: 140,
                // 	render: (h, params) => {
                // 		if (params.row.isCle == '1') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "success",
                // 		text: "是"
                // 		}
                // 		})
                // 		]);
                // 		} else if (params.row.isCle == '0') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "error",
                // 		text: "否"
                // 		}
                // 		})
                // 		]);
                // 		}
                // 	},
                // 	filters: [{
                // 		label: "是",
                // 		value: '1'
                // 		},
                // 		{
                // 		label: "否",
                // 		value: '0'
                // 		}
                // 	],
                // 	filterMultiple: false,
                // 	filterMethod(value, row) {
                // 		if (value == '1') {
                // 		return row.isCle == '1';
                // 		} else if (value == '0') {
                // 		return row.isCle == '0';
                // 		}
                // 	}
                // },
                // {
                // 	title: "CLE展商",
                // 	key: "isCleExhibitor",
                // 	align: "center",
                // 	width: 120,
                // 	render: (h, params) => {
                // 		if (params.row.isCleExhibitor == '1') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "success",
                // 		text: "是"
                // 		}
                // 		})
                // 		]);
                // 		} else if (params.row.isCleExhibitor == '0') {
                // 		return h("div", [
                // 		h("Badge", {
                // 		props: {
                // 		status: "error",
                // 		text: "否"
                // 		}
                // 		})
                // 		]);
                // 		}
                // 	},
                // 	filters: [{
                // 		label: "是",
                // 		value: '1'
                // 		},
                // 		{
                // 		label: "否",
                // 		value: '0'
                // 		}
                // 	],
                // 	filterMultiple: false,
                // 	filterMethod(value, row) {
                // 		if (value == '1') {
                // 		return row.isCleExhibitor == '1';
                // 		} else if (value == '0') {
                // 		return row.isCleExhibitor == '0';
                // 		}
                // 	}
                // },
                {
                    title: "账号状态",
                    key: "userStatus",
                    align: "center",
                    width: 120,
                    render: (h, params) => {
                        if (params.row.userStatus == 0) {
                            return h("div", [
                                h("Badge", {
                                    props: {
                                        status: "success",
                                        text: "正常启用"
                                    }
                                })
                            ]);
                        } else if (params.row.userStatus == -1) {
                            return h("div", [
                                h("Badge", {
                                    props: {
                                        status: "error",
                                        text: "禁用"
                                    }
                                })
                            ]);
                        }
                    },
                    filters: [{
                            label: "正常启用",
                            value: 0
                        },
                        {
                            label: "禁用",
                            value: -1
                        }
                    ],
                    filterMultiple: false,
                    filterMethod(value, row) {
                        if (value == 0) {
                            return row.userStatus == 0;
                        } else if (value == -1) {
                            return row.userStatus == -1;
                        }
                    }
                },
                {
                    title: "创建时间",
                    key: "createTime",
                    sortable: true,
                    sortType: "desc",
                    width: 180
                },
                {
                    title: "操作",
                    key: "action",
                    width: 200,
                    align: "center",
                    fixed: "right",
                    render: (h, params) => {
                        let enableOrDisable = "";
                        if (params.row.userStatus == 0) {
                            enableOrDisable = h(
                                "Button", {
                                    props: {
                                        size: "small"
                                    },
                                    style: {
                                        marginRight: "5px",
                                        marginTop: "5px"
                                    },
                                    on: {
                                        click: () => {
                                            this.disable(params.row);
                                        }
                                    }
                                },
                                "禁用"
                            );
                        } else {
                            enableOrDisable = h(
                                "Button", {
                                    props: {
                                        type: "success",
                                        size: "small"
                                    },
                                    style: {
                                        marginRight: "5px",
                                        marginTop: "5px"
                                    },
                                    on: {
                                        click: () => {
                                            this.enable(params.row);
                                        }
                                    }
                                },
                                "启用"
                            );
                        }
                        return h("div", [
                            h(
                                "Button", {
                                    props: {
                                        type: "success",
                                        size: "small"
                                    },
                                    style: {
                                        marginRight: "5px",
                                    },
                                    on: {
                                        click: () => {
                                            this.detail(params.row);
                                        }
                                    }
                                },
                                "企业认证信息"
                            ),
                            h(
                                "Button", {
                                    props: {
                                        type: "primary",
                                        size: "small"
                                    },
                                    style: {
                                        marginRight: "5px"
                                    },
                                    on: {
                                        click: () => {
                                            this.edit(params.row);
                                        }
                                    }
                                },
                                "编辑"
                            ),
                            enableOrDisable,
                            h(
                                "Button", {
                                    props: {
                                        type: "error",
                                        size: "small"
                                    },
                                    style: {
                                        marginTop: "5px"
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.row);
                                        }
                                    }
                                },
                                "删除"
                            )
                        ]);
                    }
                }
            ],
            data: [],
            total: 0,
            recommendTitle: "设置推荐展商",
            recommendModalVisible: false,
        };
    },
     mounted() {
        // 计算高度
        this.height = Number(document.documentElement.clientHeight - 230);
        this.init();
        console.log('mounted')
    },
    methods: {
        ...mapActions({
            enableUser: 'data/enableUser',
            disableUser: 'data/disableUser',
            resetUserPass: 'data/resetUserPass',
            setUserCle: 'data/setUserCle',
            unsetUserCle: 'data/unsetUserCle',

            getIperList: 'iper/getIperList',
            addIper: 'iper/addIper',
            editIper: 'iper/editIper',
            deleteIper: 'iper/deleteIper',
            pushHomeIper: 'iper/pushHomeIper',
            unPushHomeIper: 'iper/unPushHomeIper',
            recommendIper: 'iper/recommendIper',
            unRecommendIper: 'iper/unRecommendIper',
            cleExhibitorIper: 'iper/cleExhibitorIper',
            uncleExhibitorIper: 'iper/uncleExhibitorIper',
            sendIperMail: 'iper/sendIperMail',
        }),
        init() {
            this.getDataList();
            this.initExportColumns();
        },
        //初始化导出列数据
        initExportColumns() {
            // 初始化导出列数据
            let array = [];
            this.exportColumns.forEach(e => {
                array.push(e.title);
            });
            this.chooseColumns = array;
        },
        changePage(v) {
            this.searchForm.pageNumber = v;
            this.getDataList();
            this.clearSelectAll();
        },
        changePageSize(v) {
            this.searchForm.pageSize = v;
            this.getDataList();
        },
        selectDateRange(v) {
            if (v) {
                this.searchForm.startDate = v[0];
                this.searchForm.endDate = v[1];
            }
        },
        getDataList() {
            this.loading = true;
            console.log('getDataList')
            this.getIperList(this.searchForm).then(res => {
                this.loading = false;
                if (res.success) {
                    this.data = res.result.records;
                    this.total = res.result.total;
                }
            });
        },
        handleSearch() {
            this.searchForm.pageNumber = 1;
            this.searchForm.pageSize = 10;
            this.getDataList();
        },
        handleReset() {
            this.$refs.searchForm.resetFields();
            this.searchForm.pageNumber = 1;
            this.searchForm.pageSize = 10;
            this.selectDate = null;
            this.searchForm.startDate = "";
            this.searchForm.endDate = "";
            // 重新加载数据
            this.getDataList();
        },
        changeSort(e) {
            this.searchForm.sort = e.key;
            this.searchForm.order = e.order;
            if (e.order == "normal") {
                this.searchForm.order = "";
            }
            this.getDataList();
        },
        handleDropdown(name) {
            if (name == "refresh") {
                this.getDataList();
            } else if (name == "reset") {
                if (this.selectCount <= 0) {
                    this.$Message.warning("您还未选择要重置密码的IP方");
                    return;
                }
                this.$refs.checkPass.show();
            }
        },
        resetPass() {
            this.$Modal.confirm({
                title: "确认重置",
                content: "您确认要重置所选的 " +
                    this.selectCount +
                    " 条IP方数据密码为【123456】?",
                loading: true,
                onOk: () => {
                    let userIds = [];
                    this.selectList.forEach(function (e) {
                        userIds.push(e.userId);
                    });
                    this.resetUserPass({
                        ids: userIds.join(',')
                    }).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("操作成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        showPic(title, url, ) {
            this.fileUrl = url;
            this.picTitle = title;
            this.picVisible = true;
        },
        submitUser() {
            this.$refs.form.validate(valid => {
                if (valid) {
                    if (this.modalType == 0) {
                        // 添加 避免编辑后传入id
                        delete this.form.id;
                        delete this.form.status;
                        if (this.form.password == "" || this.form.password == undefined) {
                            this.errorPass = "密码不能为空";
                            return;
                        }
                        if (this.form.password.length < 6) {
                            this.errorPass = "密码长度不得少于6位";
                            return;
                        }
                        this.submitLoading = true;
                        this.addIper(this.form).then(res => {
                            this.submitLoading = false;
                            if (res.success) {
                                this.$Message.success("操作成功");
                                this.getDataList();
                                this.modalVisible = false;
                            }
                        });
                    } else {
                        // 编辑
                        this.submitLoading = true;
                        this.editIper(this.form).then(res => {
                            this.submitLoading = false;
                            if (res.success) {
                                this.$Message.success("操作成功");
                                this.getDataList();
                                this.modalVisible = false;
                            }
                        });
                    }
                }
            });
        },
        add() {
            this.modalType = 0;
            this.modalTitle = "添加IP方";
            this.$refs.form.resetFields();
            this.modalVisible = true;
        },
        edit(v) {
            this.modalType = 1;
            this.modalTitle = "编辑IP方";
            this.$refs.form.resetFields();
            // 转换null为""
            for (let attr in v) {
                if (v[attr] == null) {
                    v[attr] = "";
                }
            }
            let str = JSON.stringify(v);
            let data = JSON.parse(str);
            this.form = data;
            this.modalVisible = true;
        },
        enable(v) {
            this.$Modal.confirm({
                title: "确认启用",
                content: "您确认要启用 " + v.username + " ?",
                loading: true,
                onOk: () => {
                    this.enableUser(v.userId).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("操作成功");
                            this.getDataList();
                        }
                    });
                }
            });
        },
        disable(v) {
            this.$Modal.confirm({
                title: "确认禁用",
                content: "您确认要禁用 " + v.username + " ?",
                loading: true,
                onOk: () => {
                    this.disableUser(v.userId).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("操作成功");
                            this.getDataList();
                        }
                    });
                }
            });
        },
        remove(v) {
            this.$Modal.confirm({
                title: "确认删除",
                content: "您确认要删除 " + v.username + " ?",
                loading: true,
                onOk: () => {
                    this.deleteIper(v.id).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("删除成功");
                            this.getDataList();
                        }
                    });
                }
            });
        },
        showSelect(e) {
            this.exportData = e;
            this.selectList = e;
            this.selectCount = e.length;
        },
        clearSelectAll() {
            this.$refs.table.selectAll(false);
        },
        delAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要删除的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认删除",
                content: "您确认要删除所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let ids = [];
                    this.selectList.forEach(function (e) {
                        ids.push(e.id)
                    });
                    this.deleteIper(ids.join(',')).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("删除成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        //推送首页
        pushHomeAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要推送的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认推送首页",
                content: "您确认要推送首页所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let ids = [];
                    this.selectList.forEach(function (e) {
                        ids.push(e.id);
                    });
                    this.pushHomeIper(ids.join(',')).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("推送首页成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        //取消推送首页
        unPushHomeAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要取消的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认取消推送首页",
                content: "您确认要取消推送所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let ids = [];
                    this.selectList.forEach(function (e) {
                        ids.push(e.id);
                    });
                    this.unPushHomeIper(ids.join(',')).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("取消推送首页成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        showRecommend() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要设置的数据");
                return;
            }
            this.sortOrder = 1;
            this.recommendModalVisible = true;

        },
        //推荐展商
        recommendAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要推荐的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认推荐展商",
                content: "您确认要推荐展商所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let ids = [];
                    this.selectList.forEach(function (e) {
                        ids.push(e.id);
                    });
                    this.recommendIper(ids.join(','), {
                        sortOrder: this.sortOrder
                    }).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("推荐展商成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        //取消推荐展商
        unRecommendAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要取消的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认取消推荐展商",
                content: "您确认要取消推荐所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let ids = [];
                    this.selectList.forEach(function (e) {
                        ids.push(e.id);
                    });
                    this.unRecommendIper(ids.join(',')).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("取消推荐展商成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },

        //设置CLE
        setCleAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要设置的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认设置专委会会员",
                content: "您确认要设置所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let userIds = [];
                    this.selectList.forEach(function (e) {
                        userIds.push(e.userId);
                    });
                    this.setUserCle({
                        ids: userIds.join(',')
                    }).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("设置成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        //取消设置CLE
        unsetCleAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要取消的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认取消设置专委会会员",
                content: "您确认要取消所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let userIds = [];
                    this.selectList.forEach(function (e) {
                        userIds.push(e.userId);
                    });
                    this.unsetUserCle({
                        ids: userIds.join(',')
                    }).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("取消成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        //设置CLE展商
        cleExhibitorAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要设置的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认设置CLE展商",
                content: "您确认要设置所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let ids = [];
                    this.selectList.forEach(function (e) {
                        ids.push(e.id);
                    });
                    this.cleExhibitorIper(ids.join(',')).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("设置成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        //取消设置CLE展商
        uncleExhibitorAll() {
            if (this.selectCount <= 0) {
                this.$Message.warning("您还未选择要取消的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认取消CLE展商",
                content: "您确认要取消所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let ids = [];
                    this.selectList.forEach(function (e) {
                        ids.push(e.id);
                    });
                    this.uncleExhibitorIper(ids.join(',')).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("取消成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });
        },
        sendMail() {
            if (this.selectCount <= 0) {
                this.$Message.warning("请选择要发送的数据");
                return;
            }
            this.$Modal.confirm({
                title: "确认发送邮件",
                content: "您确认要发送所选的 " + this.selectCount + " 条数据?",
                loading: true,
                onOk: () => {
                    let userIds = "";
                    this.selectList.forEach(function (e) {
                        userIds += e.userId + ",";
                    });
                    userIds = userIds.substring(0, userIds.length - 1);
                    this.sendIperMail({
                        userIds: userIds
                    }).then(res => {
                        this.$Modal.remove();
                        if (res.success) {
                            this.$Message.success("操作成功");
                            this.clearSelectAll();
                            this.getDataList();
                        }
                    });
                }
            });

        },

        detail(v) {
            let query = {
                backRoute: this.$route.path
            };
            this.$router.push({
                path: `/iperDetail/${v.id}`,
                query: query
            });
        },
        handleDropdownExport(name) {
            if (name == "search") {
                this.exportType = "all";
                this.exportModalVisible = true;
                this.exportTitle = "确认导出全部 " + this.total + " 条数据";
                let searchForm = {};
                for (let v in this.searchForm) {
                    searchForm[v] = this.searchForm[v];
                }
                searchForm.pageNumber = 1;
                searchForm.pageSize = 2147483647;
                this.getIperList(searchForm).then(res => {
                    if (res.success) {
                        this.exportData = res.result.records;
                    }
                });
            } else if (name == "selected") {
                if (this.selectCount <= 0) {
                    this.$Message.warning("您还未选择要导出的数据");
                    return;
                }
                this.exportType = "part";
                this.exportModalVisible = true;
                this.exportTitle = "确认导出 " + this.selectCount + " 条数据";
            }
        },
        exportCustomData() {
            if (this.filename == "") {
                this.filename = "导出数据";
            }
            // 判断勾选导出列
            let array = [];
            this.exportColumns.forEach(e => {
                this.chooseColumns.forEach(c => {
                    if (e.title == c && !e.disabled) {
                        array.push(e);
                    }
                });
            });
            this.exportModalVisible = false;
            victorExcel.downloadExl({
                exportColumn: array,
                data: this.exportData,
                fileName: this.filename,
            });

        },
    },
   
};
</script>
